package com.shw.pclient.adapter;

import java.util.List;
import java.util.Vector;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.shw.pclient.R;
import com.shw.pclient.vo.ImageInfo;
/**
 * 
 * @author HAHA
 *
 */
public class SHWImageAdapter extends BaseAdapter {

	public static Vector<String> vector = new Vector<String>();

	private Context context;
	private List<ImageInfo> imageInfos;
	private LayoutInflater layoutInflater;

	private class ListHolder {
		ImageView imageView;
		TextView textView;
	}

	public SHWImageAdapter(Context context) {
		super();
		this.context = context;
	}

	public void setList(List<ImageInfo> imageInfos) {
		this.imageInfos = imageInfos;
		layoutInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return imageInfos.size();
	}

	@Override
	public Object getItem(int arg0) {
		return imageInfos.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		ListHolder listHolder;
		if (arg1 == null) {
			arg1 = layoutInflater.inflate(R.layout.image_item, null);
			listHolder = new ListHolder();
			listHolder.imageView = (ImageView) arg1.findViewById(R.id.shw_img);
			listHolder.textView = (TextView) arg1
					.findViewById(R.id.shw_img_date);
			arg1.setTag(listHolder);
		} else {
			listHolder = (ListHolder) arg1.getTag();
		}
		ImageInfo imageInfo = imageInfos.get(arg0);
		if (imageInfo != null) {
			listHolder.textView.setText(imageInfo.getName());
			Bitmap b = BitmapFactory.decodeFile(imageInfo
					.getImgPath());
			listHolder.imageView.setImageBitmap(b);
		}
		return arg1;
	}

}
